package cn.csq.netty.bio;

import java.io.*;
import java.net.Socket;

public class BIOClient {
    public static void main(String[] args) {
        //Socket socket = new Socket();
        // socket.connect(6666, 20);

        try {
            //与服务器创建连接
            Socket socket1 = new Socket("localhost", 8080);

            //发送给服务器信息
            OutputStream outputStream = socket1.getOutputStream();

            PrintWriter printWriter = new PrintWriter(outputStream);

            printWriter.write("我收到了信息");
            printWriter.flush();

            socket1.shutdownOutput();

            //接收信息
            InputStream inputStream = socket1.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            String info = null;
            while ((info = bufferedReader.readLine()) != null) {
                System.out.println("我是客户端，服务器返回信息：" + info);
            }
            bufferedReader.close();
            inputStream.close();
            outputStream.close();
            printWriter.close();
            socket1.close();

        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
